#include <iostream>

using namespace std;

// c++函数
bool MySort(int a, int b)
{
  return a > b;
}

void Display(int a)
{
  cout << a << " ";
}

// 泛型（模板）函数
template <class T>
inline bool MySortT(T const &a, T const &b)
{
  return a > b;
}

template <class T>
inline void DisplayT(T const &a)
{
  cout << a << " ";
}

// 仿函数
struct MySortF
{
  bool operator()(int a, int b)
  {
    return a > b;
  }
};

struct DisplayF
{
  void operator()(int a)
  {
    cout << a << " ";
  }
};

// 仿函数模板
template<class T>
struct MySortTF
{
  bool operator()(T const &a, T const &b) const
  {
    return a > b;
  }
};

template<class T>
struct DisplayTF
{
  void operator()(T const &a) const
  {
    cout << a << " ";
  }
};

int main()
{

  int arr1[] = {1, 4, 5, 3, 8};
  sort(arr1, arr1 + 5, MySort);
  for_each(arr1, arr1 + 5, Display);
  cout << endl;

  int arr2[] = {1, 4, 5, 3, 8};
  sort(arr2, arr2 + 5, MySortT<int>);
  for_each(arr2, arr2 + 5, DisplayT<int>);
  cout << endl;

  int arr3[] = {1, 4, 5, 3, 8};
  sort(arr3, arr3 + 5, MySortF());
  for_each(arr3, arr3 + 5, DisplayF());
  cout << endl;

  int arr4[] = {1, 4, 5, 3, 8};
  sort(arr4, arr4 + 5, MySortF());
  for_each(arr4, arr4 + 5, DisplayF());
  cout << endl;

  return 0;
}